﻿<%@ Page Language="VB" MasterPageFile="~/Print.master" Title="Untitled Page" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>

<%@ Register Assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
    Namespace="System.Web.UI" TagPrefix="asp" %>

<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.Sql" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="ClubStarterKit.Data" %>
<%@ Import Namespace="SubSonic" %>

<%@ Register TagPrefix="Club" TagName="LoginBanner" Src="~/UserControls/LoginBanner.ascx" %>
<%@ Register TagPrefix="Club" TagName="ImageThumbnail" Src="~/UserControls/ImageThumbnail.ascx" %>

<script runat="server">

    Public MaxAddToRSVP As Integer
   
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
        If Request("eventid") Is Nothing Then
            Response.Redirect("~/events/view.aspx?eventid=1")
        End If

        If IsPostBack = False Then
            InitRSVP()

            panel1.Visible = User.IsInRole("Administrators")
            
            ClubStarterKit.Web.Events.RSVPSanityCheck(EventID)
        End If
    End Sub
    
    Protected Sub InitRSVP()
        Dim TheEvent As New ClubEvent(EventID)
        If TheEvent.IsLoaded = True Then
            If TheEvent.RSVP = True Then
                If User.Identity.IsAuthenticated = True Then
                    StatusLabel.Text = "This event requires an RSVP."
                Else
                    StatusLabel.Text = "This event requires an RSVP. Please login to RSVP."
                End If
            Else
                StatusLabel.Text = "This event doesn't require an RSVP."
            End If
        Else
            StatusLabel.Text = ""
        End If
    End Sub
    
    
    Function ShowLocationLink(ByVal locationname As Object, ByVal locationdirections As Object) As String
        If (Not locationname Is Nothing) AndAlso Not IsDBNull(locationname) Then
            Return "At " & "<a href='../Locations/view.aspx?LocationID=" & CStr(locationname) & "'>" & CStr(locationname) & "</a><br/>"
        Else
            Return ""
        End If
    End Function
    
    Function StartDT(ByVal starttime As Object) As String
        Dim starttimeDT As Date = CDate(starttime)
        If Not starttime Is Nothing AndAlso Not IsDBNull(starttime) Then
            Return starttimeDT.ToLongDateString() & " at " & starttimeDT.ToShortTimeString()
        Else
            Return " "
        End If
    End Function
    
    Function EndDT(ByVal endtime As Object) As String
        Dim endtimeDT As Date = CDate(endtime)
        If Not endtime Is Nothing AndAlso Not IsDBNull(endtime) Then
            Return "to " & endtimeDT.ToLongDateString() & " at " & endtimeDT.ToShortTimeString()
        Else
            Return " "
        End If
    End Function
    
    Property EventID() As Integer
        Get
            Dim m_EventID As Integer
            Dim id As Object = ViewState("EventID")
            If Not id Is Nothing AndAlso IsNumeric(id) Then
                m_EventID = CInt(id)
            Else
                id = Request.QueryString("EventID")
                If Not id Is Nothing AndAlso IsNumeric(id) Then
                    m_EventID = CInt(id)
                Else
                    m_EventID = 1
                End If
                
                ViewState("EventID") = m_EventID
            End If
            Return m_EventID
        End Get
        Set(ByVal value As Integer)
            ViewState("EventID") = value
        End Set
    End Property

</script>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<div id="body">
    &nbsp;
        <div id="columnleft">
            <div class="leftblock">
            <h2>
                <asp:FormView ID="FormView" runat="server" DataSourceID="ObjectDataSource1">
                    <ItemTemplate>
<h2>
                            <asp:Label Text='<%# Eval("title") %>' runat="server" ID="titleLabel" />
                        </h2>
                        <div class="itemdetails">
                            <br />
                            <h3>
                                <asp:Label ID="locationLabel" runat="server" Text='<%# ShowLocationLink(Eval("LocationName"),Eval("LocationDirections")) %>' />
                            </h3>
                            <p>
                                <asp:Label Text='<%# StartDT(Eval("starttime")) %>' runat="server" ID="itemdateLabel" />
                                <br />
                                <asp:Label Text='<%# EndDT(Eval("endtime")) %>' runat="server"
                                    ID="Label1" />
                            </p>
                            <p>
                                <asp:Label Font-Size="Smaller" Text='<%# Eval("description") %>' runat="server" ID="descriptionLabel" />&nbsp;</p>
                        </div>
                        <div class="downloadevent">
                            &nbsp;</div>
                        <Club:ImageThumbnail ID="thumb1" runat="server" ImageSize="Large" PhotoID='<%# Eval("photo") %>' />                    </ItemTemplate>
                </asp:FormView>
                &nbsp;</h2>
                <h2>
                    RSVP</h2>
            <br />
            <asp:Label ID="StatusLabel" runat="server" />
                <asp:ObjectDataSource ID="RSVPSource" runat="server" SelectMethod="OpenRSVP" TypeName="ClubStarterKit.Web.Events">
                    <SelectParameters>
                        <asp:QueryStringParameter Name="EventID" QueryStringField="eventid" Type="Int32" />
                    </SelectParameters>
                </asp:ObjectDataSource>
                <br />
                <div id="RSVPDiv" runat="server" visible="false">
                    <br />
                   <br />
                   <asp:Label ID="RSVPTTLStatus" runat="server" />
                   <asp:GridView id="RSVPGrid" runat="server" DataSourceID="RSVPSource" Width="208px" BorderWidth="1px" BorderStyle="None" BackColor="White" BorderColor="#CCCCCC" CellPadding="3" DataMember="DefaultView" AutoGenerateColumns="False" Visible='<%# User.IsInRole("Administrators") %>'>
                    <FooterStyle BackColor="White" ForeColor="#000066" />
                    <RowStyle ForeColor="#000066" HorizontalAlign="Center" />
                    <SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
                    <HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />
                    <Columns>
                        <asp:TemplateField SortExpression="avatar">
                            <ItemTemplate>
                                <asp:Image ID="Image1" runat="server" ImageUrl='<%# "~/UserControls/AvatarImagefetch.ashx?MemberId=" & DataBinder.Eval(Container.DataItem,"UserId").ToString %>' ToolTip='<%# Eval("UserName") %>' />
                            </ItemTemplate>
                            <ItemStyle Width="104px" />
                        </asp:TemplateField>
                        <asp:TemplateField SortExpression="guests">
                            <ItemTemplate>
                                <asp:Label ID="lblguests" runat="server" Text='<%# Eval("numofguest") %>' />
                            </ItemTemplate>
                            <ItemStyle Width="104px" />
                        </asp:TemplateField>
                    </Columns>
                    <EmptyDataTemplate>
                    No one has sent an RSVP for this event.
                    </EmptyDataTemplate>
                </asp:GridView>
                </div>
                
            </div>
        </div>
                <div id="columnright">
            <div class="rightblock">
                <br />
                <a href="list.aspx"></a>&nbsp;</div>
                <div class="rightblock">
                    &nbsp;<div id="panel1" runat="server" class="actionbuttons">
                        &nbsp;</div>
                    
                    <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="FetchByParameter"
                        TypeName="ClubStarterKit.Data.ClubEvent">
                        <SelectParameters>
                            <asp:Parameter DefaultValue="ID" Name="columnName" Type="String" />
                            <asp:Parameter DefaultValue="" Name="comparison" Type="Object" />
                            <asp:QueryStringParameter DefaultValue="" Name="oValue" QueryStringField="EventID"
                                Type="Object" />
                        </SelectParameters>
                    </asp:ObjectDataSource>
                    <br />
                </div>
        </div>
        </div>
</asp:Content>